﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace WindowsFormsApplication1
{
    public partial class newbill : UserControl
    {
        public newbill()
        {
            InitializeComponent();
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            string connection = "Data Source=|DataDirectory|\\Model\\Database1.sdf";
            string[] x1 = new string[6] { "@apID", "@uname", "@Type", "@onm", "@Shov", "@Price" };
            string[] values1 = new string[6] { "" + Globals.dept, Globals.userName, "" + Globals.billtype, txt_month.Text, txt_sho.Text, txt_price.Text };
            string q1 = "INSERT INTO bills (apartmentID,Name,Type,OnMonths,Shovar,Price) VALUES(@apID, @uname, @type, @onm,@shov, @Price)";

            if (Controller.Control.Insert_Update(q1,connection,x1,values1)==1)
            {
                MessageBox.Show("new bill payment was added!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            string q2 = "UPDATE balance SET bala = bala+@Price WHERE userID = @userID ";
            string[] x2 = new string[2] { "@userID", "@Price" };
            string[] values2 = new string[2] { "" + Globals.userID, txt_price.Text };
            if (Controller.Control.Insert_Update(q2, connection, x2, values2) == 1)
                MessageBox.Show("balance was updated!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
